package com.ruoyi.admin.controller;

import com.ruoyi.app.domain.ArticleInfo;
import com.ruoyi.app.dto.ArticleDto;
import com.ruoyi.app.service.HomeService;
import com.ruoyi.app.service.PermissionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/*
@description:
@ClassName ArticleInfoController
@author chen
@create 2025-03-25 20:55
@Version 1.0
*/
@Slf4j
@RestController
@RequestMapping("article")
@AllArgsConstructor
public class ArticleInfoController extends BaseController
{

    final PermissionService permissionService;
    final HomeService homeService;


    /*
     * @==============History===============<br/>;
     * @Description //   用户发表文章
     * @Date 2025/3/14
     * @Author < a href="chencheng@prmt.net">chen</ a>;
     */
    @PostMapping(value = "/insertArticleInfo",produces = "application/json;charset=utf-8")
    public AjaxResult insertArticleInfo(@RequestBody ArticleInfo articleInfo)
    {
        return permissionService.insertArticleInfo(articleInfo);
    }


    /*
     * @==============History===============<br/>;
     * @Description // 根据文章id获取文章详情
     * @Date 2025/3/18
     * @Author < a href="chencheng@prmt.net">chen</ a>;
     */
    @GetMapping(value = "/getArticleInfo",produces = "application/json;charset=utf-8")
    public AjaxResult getArticleInfo(@RequestParam Map<String, Object> params)
    {
        return AjaxResult.success(homeService.getArticleInfo(params));
    }


    /*
     * @==============History===============<br/>
     * @Description //   获取文章列表
     * @Date 2025-3-27 21:31
     * @Author < a href="15991488967@163.com">chen</ a>
     * @return com.ruoyi.framework.web.domain.AjaxResult
     */
    @GetMapping(value = "/getArticleInfoList",produces = "application/json;charset=utf-8")
    public TableDataInfo getArticleInfoList(@RequestParam Map<String, Object> params)
    {
        startPage();
        List<ArticleDto> list = homeService.getArticleInfoList(params);
        return getDataTable(list);
    }

    /*
     * @==============History===============<br/>;
     * @Description //   用户更新文章
     * @Date 2025/3/18
     * @Author < a href="chencheng@prmt.net">chen</ a>;
     */
    @PostMapping(value = "/updateArticleInfo",produces = "application/json;charset=utf-8")
    public AjaxResult updateArticleInfo(@RequestBody ArticleInfo articleInfo)
    {
        return permissionService.updateArticleInfo(articleInfo);
    }

    /*
     * @==============History===============<br/>
     * @Description //   用户删除文章
     * @Date 2025-3-18 19:28
     * @Author < a href="15991488967@163.com">chen</ a>
     * @return com.ruoyi.framework.web.domain.AjaxResult
     */
    @DeleteMapping(value = "/deleteArticleInfo",produces = "application/json;charset=utf-8")
    public AjaxResult deleteArticleInfo(@RequestParam Long id)
    {
        return permissionService.deleteArticleInfo(id);
    }

}
